package com.commerce.afive;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import org.w3c.dom.Text;

public class SecondActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_second);
        Button btnToActivity = findViewById(R.id.sd_btn_toActivity);
        Button btnToThird = findViewById(R.id.sd_btn_toThird);
        Button btnToThird2 = findViewById(R.id.sd_btn_toThird2);
        Button btnReturn = findViewById(R.id.sd_btn_toReturn);
        TextView text = findViewById(R.id.sd_tv_text);
        text.setText(getIntent().getStringExtra("extra_data"));
        btnToActivity.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent("android.intent.action.MAIN").addCategory("android.intent.category.MainActivity"));
            }
        });
        btnToThird.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse("http:www.6080a.net")));
            }
        });
        btnToThird2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(Intent.ACTION_DIAL).setData(Uri.parse("tel:10086")));
            }
        });
        btnReturn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                setResult(2,new Intent().putExtra("data_return","hello MainActivity"));
                finish();
            }
        });
    }

    @Override
    public void onBackPressed() {
        setResult(2,new Intent().putExtra("data_return","hello MainActivity"));
        finish();
    }
}